package com.sexymobileframework.uicomponent;

import java.util.ArrayList;
import java.lang.reflect.Field;


import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class UIComponent 
{
	public static final int UICOMPONENT_TYPE_NULL = -1;
	public static final int UICOMPONENT_TYPE_MENU = 0;
	public static final int UICOMPONENT_TYPE_MENUITEM = 1;
	
	public String m_id;
	public int m_type;
	public UIComponent m_parent;
	public ArrayList<UIComponent> m_child;
	
	public UIComponent()
	{
		m_id = "";
		m_type =  UICOMPONENT_TYPE_NULL;
		m_parent = null;
		m_child = new ArrayList<UIComponent>();
	}
	
	public UIComponent(Node UIComponentNode)
	{
		//init id
		m_id = UIComponentNode.getAttributes().getNamedItem("id").getNodeValue();
		
		//init type
		try
		{
			String prefix = new String("UICOMPONENT_TYPE_");
			
			String UIComponentType = prefix + UIComponentNode.getNodeName().toUpperCase();
			
			Field type = UIComponent.class.getDeclaredField(UIComponentType);
			
			m_type = type.getInt(UIComponent.class);
			
		}
		catch (NoSuchFieldException e) 
		{
			e.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		//init parent
		m_parent = null;
		
		m_child = new ArrayList<UIComponent>();
	}
	
	public void setID(String id)
	{
		m_id = id;
	}
	
	public void setType(int type)
	{
		m_type = type;
	}
	
	public void setParent(UIComponent parent)
	{
		m_parent = parent;
	}
	
	public void addChild(UIComponent child)
	{
		m_child.add(child);
	}
	
	public String getID()
	{
		return m_id;
	}
	
	public int getType()
	{
		return m_type;
	}
	
	public UIComponent getParent()
	{
		return m_parent;
	}
}
